'''
Created on Mar 27, 2014

@author: pan
'''

import ROOT
import numpy
import matplotlib

import os
import os.path

from ROOT import gROOT, TCanvas,TFile,gStyle, TH1F, TH2F

gROOT.SetStyle("Plain")
gROOT.ForceStyle()

PATH = u"~/example_CT/classic"
ROOTFILE = u"benchmarkCT.root"

rootfile = TFile(os.path.join(PATH, ROOTFILE) )

# print rootfile.ls()
#coinsidences should be TTree 
coinsidences = rootfile.Get("Singles")

# print coinsidences.Print()

canv = TCanvas("canvas for sinogram","resultats",200,10,1000,1000);
canv.SetFillColor(0);
canv.SetBorderMode(0);
canv.SetLeftMargin(0.1409396);  
canv.SetRightMargin(0.04865772);

gStyle.SetOptStat(000)

LbinR = 0.5
Rmin = -100
Rmax = 100
NbinR = int((Rmax-Rmin)/LbinR)

LbinT = .02#degre  
Tmin = 0 
Tmax = 3.2 
NbinT = int((Tmax-Tmin)/LbinT)

rho         = TH1F("RHO", "RHO", NbinR, Rmin, Rmax)
Sinogramme  = TH2F("Sinogram","Sinogram",NbinR, Rmin, Rmax, NbinT, Tmin, Tmax)

print "1."+str(int(LbinR)) +""
print "1."+str(int(LbinR/LbinT))

coinsidences.Draw("sinogramS>>RHO", "1."+str(int(LbinR)), "goff")
coinsidences.Draw("sinogramTheta:sinogramS>>Sinogramme", "1."+str(int(LbinR/LbinT)), "goff")

canv.Divide(1,2)
canv.cd(1)

Sinogramme.Draw("COLZ")
Sinogramme.SetTitle("")
Sinogramme.GetXaxis()

canv.cd(2)
rho.Draw()

Sinogramme.GetXaxis().SetTitle("rho (mm)")
Sinogramme.GetYaxis().SetTitle("theta (radian)")

rho.GetXaxis().SetTitle("rho (mm)")

output_name = os.path.splitext(ROOTFILE)[0] + ".pdf"
canv.SaveAs(os.path.join(PATH, output_name))



